import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "DBshop01_退款处理"

driver = openBrowser(urlAdmin)
# 登录后台
driver.get(urlAdmin)
DBshopLoginAdmin(driver)

rootPath = get_pro_rootpath() #获取项目的绝对路径
filePath = rootPath+r'\public\order1.txt' #拼接文件路径
orderNo = readFile(filePath) #读取文件中的订单编号

# 处理二级菜单
DBshopEnterMenu2(driver,"销售管理","退货管理")
# 文本框输入订单号
driver.find_element_by_xpath("//input[@name = 'order_sn']").send_keys(orderNo)
# 定位下拉框
driver.find_element_by_xpath("//select[@name = 'refund_type']/option[2]").click()
# 点击搜索按钮
driver.find_element_by_xpath("(//button)[1]").click()
# 点击处理退货
driver.find_element_by_link_text("处理退货").click()
# 退款金额
driver.find_element_by_id("refund_price").send_keys("2199")
# 退款意见
driver.find_element_by_id("re_refund_info").send_keys("同意")
# 点击同意退款
driver.find_element_by_xpath("//button").click()

# 前台登录
driver.get(url)
DBshopLogin(driver,userName,password)
# 点击用户中心，退货申请
driver.find_element_by_link_text("用户中心").click()
driver.find_element_by_link_text("退货申请").click()
# 得到处理结果 存入变量
retule = driver.find_element_by_xpath("//tbody/tr[1]/td[4]").text

if retule == "退款成功":
    writeLog("%s 测试通过,退款成功" % testCase)
else:
    writeLog("%s 测试不通过" % testCase)
    getPhoto(driver)
driver.quit()